from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-14 14:10:52.259661
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 14, Apr, 2021
Time: 14:10:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5114
Nobs: 261.000 HQIC: -48.2464
Log likelihood: 3117.55 FPE: 6.79845e-22
AIC: -48.7405 Det(Omega_mle): 4.84675e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.448560 0.124955 3.590 0.000
L1.Burgenland 0.069074 0.062119 1.112 0.266
L1.Kärnten -0.222066 0.053991 -4.113 0.000
L1.Niederösterreich 0.073699 0.134152 0.549 0.583
L1.Oberösterreich 0.220314 0.126957 1.735 0.083
L1.Salzburg 0.270809 0.070179 3.859 0.000
L1.Steiermark 0.126804 0.089602 1.415 0.157
L1.Tirol 0.123252 0.061541 2.003 0.045
L1.Vorarlberg -0.037400 0.056649 -0.660 0.509
L1.Wien -0.061442 0.115750 -0.531 0.596
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.487090 0.146090 3.334 0.001
L1.Burgenland -0.004047 0.072625 -0.056 0.956
L1.Kärnten 0.329296 0.063122 5.217 0.000
L1.Niederösterreich 0.076487 0.156842 0.488 0.626
L1.Oberösterreich -0.061717 0.148430 -0.416 0.678
L1.Salzburg 0.221817 0.082048 2.703 0.007
L1.Steiermark 0.109740 0.104756 1.048 0.295
L1.Tirol 0.143037 0.071949 1.988 0.047
L1.Vorarlberg 0.154733 0.066230 2.336 0.019
L1.Wien -0.443854 0.135327 -3.280 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.289000 0.062526 4.622 0.000
L1.Burgenland 0.090714 0.031083 2.918 0.004
L1.Kärnten -0.018104 0.027016 -0.670 0.503
L1.Niederösterreich 0.057341 0.067128 0.854 0.393
L1.Oberösterreich 0.277134 0.063527 4.362 0.000
L1.Salzburg 0.024749 0.035116 0.705 0.481
L1.Steiermark 0.009971 0.044835 0.222 0.824
L1.Tirol 0.072849 0.030794 2.366 0.018
L1.Vorarlberg 0.081529 0.028346 2.876 0.004
L1.Wien 0.119153 0.057920 2.057 0.040
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.217962 0.061168 3.563 0.000
L1.Burgenland 0.021829 0.030409 0.718 0.473
L1.Kärnten 0.008936 0.026430 0.338 0.735
L1.Niederösterreich 0.053324 0.065670 0.812 0.417
L1.Oberösterreich 0.400788 0.062148 6.449 0.000
L1.Salzburg 0.082347 0.034354 2.397 0.017
L1.Steiermark 0.128977 0.043862 2.941 0.003
L1.Tirol 0.050017 0.030126 1.660 0.097
L1.Vorarlberg 0.084799 0.027731 3.058 0.002
L1.Wien -0.048807 0.056662 -0.861 0.389
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.502402 0.119484 4.205 0.000
L1.Burgenland 0.089377 0.059399 1.505 0.132
L1.Kärnten 0.011560 0.051627 0.224 0.823
L1.Niederösterreich 0.002474 0.128278 0.019 0.985
L1.Oberösterreich 0.131180 0.121398 1.081 0.280
L1.Salzburg 0.058723 0.067106 0.875 0.382
L1.Steiermark 0.067706 0.085678 0.790 0.429
L1.Tirol 0.213440 0.058846 3.627 0.000
L1.Vorarlberg 0.031429 0.054168 0.580 0.562
L1.Wien -0.100468 0.110682 -0.908 0.364
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188977 0.094497 2.000 0.046
L1.Burgenland -0.012412 0.046977 -0.264 0.792
L1.Kärnten -0.007590 0.040830 -0.186 0.853
L1.Niederösterreich -0.002995 0.101452 -0.030 0.976
L1.Oberösterreich 0.398791 0.096011 4.154 0.000
L1.Salzburg 0.016336 0.053072 0.308 0.758
L1.Steiermark -0.019345 0.067761 -0.285 0.775
L1.Tirol 0.158883 0.046540 3.414 0.001
L1.Vorarlberg 0.053425 0.042841 1.247 0.212
L1.Wien 0.230958 0.087536 2.638 0.008
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.238690 0.115042 2.075 0.038
L1.Burgenland 0.019484 0.057191 0.341 0.733
L1.Kärnten -0.068856 0.049707 -1.385 0.166
L1.Niederösterreich -0.069965 0.123509 -0.566 0.571
L1.Oberösterreich 0.019081 0.116885 0.163 0.870
L1.Salzburg 0.082625 0.064611 1.279 0.201
L1.Steiermark 0.335747 0.082493 4.070 0.000
L1.Tirol 0.461587 0.056658 8.147 0.000
L1.Vorarlberg 0.148137 0.052155 2.840 0.005
L1.Wien -0.162197 0.106567 -1.522 0.128
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182739 0.137323 1.331 0.183
L1.Burgenland 0.040572 0.068267 0.594 0.552
L1.Kärnten -0.074842 0.059334 -1.261 0.207
L1.Niederösterreich 0.132208 0.147429 0.897 0.370
L1.Oberösterreich 0.017185 0.139523 0.123 0.902
L1.Salzburg 0.200042 0.077124 2.594 0.009
L1.Steiermark 0.117210 0.098470 1.190 0.234
L1.Tirol 0.057626 0.067632 0.852 0.394
L1.Vorarlberg 0.103433 0.062256 1.661 0.097
L1.Wien 0.230149 0.127206 1.809 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.565332 0.074222 7.617 0.000
L1.Burgenland -0.032427 0.036898 -0.879 0.379
L1.Kärnten -0.023660 0.032070 -0.738 0.461
L1.Niederösterreich 0.043551 0.079684 0.547 0.585
L1.Oberösterreich 0.315012 0.075411 4.177 0.000
L1.Salzburg 0.022147 0.041685 0.531 0.595
L1.Steiermark -0.033981 0.053222 -0.638 0.523
L1.Tirol 0.087013 0.036554 2.380 0.017
L1.Vorarlberg 0.110366 0.033649 3.280 0.001
L1.Wien -0.046592 0.068754 -0.678 0.498
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.144909 0.079104 0.163727 0.219821 0.080520 0.082478 0.013946 0.146320
Kärnten 0.144909 1.000000 0.035908 0.202630 0.178249 -0.061913 0.163741 0.026235 0.302705
Niederösterreich 0.079104 0.035908 1.000000 0.235389 0.075822 0.323905 0.140884 0.027646 0.291983
Oberösterreich 0.163727 0.202630 0.235389 1.000000 0.300544 0.268228 0.089037 0.059489 0.133781
Salzburg 0.219821 0.178249 0.075822 0.300544 1.000000 0.154669 0.053101 0.088332 0.006946
Steiermark 0.080520 -0.061913 0.323905 0.268228 0.154669 1.000000 0.103772 0.095873 -0.107190
Tirol 0.082478 0.163741 0.140884 0.089037 0.053101 0.103772 1.000000 0.161742 0.148069
Vorarlberg 0.013946 0.026235 0.027646 0.059489 0.088332 0.095873 0.161742 1.000000 -0.008315
Wien 0.146320 0.302705 0.291983 0.133781 0.006946 -0.107190 0.148069 -0.008315 1.000000